﻿package ygg.encoding.amf.type.v3
{
	import flash.utils.ByteArray;
	import ygg.encoding.amf.type.*;
	import j.sus2maj7.encoding.*;
	
	public class ByteArrayCodec extends ComplexCodec
	{
		public function ByteArrayCodec()
		{
			
		}
		
		override protected function decodeComplex(u:uint, binary:IBinary, context:IContext=null):*
		{
			trace('ByteArrayCodec');
			var retVal:ByteArray = new ByteArray();
			binary.readBytes(retVal, 0, u);
			return retVal;
		}
		
		override protected function encodeComplex(o:Object, b:IBinary, context:IContext=null):void
		{
			var ba:ByteArray = o as ByteArray;
			b.writeByte(ba.length << 1 | 1);
			
			b.writeBytes(ba);
			
			
		}
		override protected function getMarker():uint
		{
			return Amf3Marker.BYTEARRAY;
		}
	}
}